using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Facebook.Service;
using AjaxNinja.Data;
using AjaxNinja.Types;
using Snap.Diagnostics;

public partial class Install_PostAdd : System.Web.UI.Page
{
    private SQLDb db;
    private Diagnostics dg;
    protected void Page_Load(object sender, EventArgs e)
    {

        //Get our SQL Data writer ready
        db = new SQLDb();
        //Get our error trapping utility ready
        //NOTE: the Diagnostics class can be used with ANY ASP.NET application so
        //long as the tables and required stored procedure are available.
        //Thus when we initialize a diagnostics instance we have to provide a name
        //for the connection string since it's not tailored for a specific application
        dg = new Diagnostics("fbConnectionString");

        try
        {
            //Check to see if this user already exists (they may have removed
            //the app then added it again later)
            int userID = Int32.Parse(Master.fbApp.UserID);
            db.AddUser(userID); //Add the user to our database
        }
        //We're going to trap general exceptions because there is no telling what
        //kind of awesome exceptions the Facebook platform might throw at us, so
        //it limits us a bit in determining what the most specific error is but
        //we still have the capability of logging any internal errors that may occur
        catch (Exception err)
        {
            SError logMsg = new SError("postAdd.aspx", err.TargetSite.Name, Master.fbApp.UserID, 0, err.Message + err.StackTrace);
            dg.logError(logMsg); //Commit the error to database
        }
    }
}
